package net.zjitc.arrays;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class TriMat {
    private int row;
    private int col;
    private int count;//非0值个数

    public int getCount() {
        return count;
    }

    private List<Triple> list;

    public TriMat() {
         list =  new ArrayList<>();
    }


    //给一个矩阵，对其进行压缩存储
    public void createTriple(int[][] arr){
       row = arr.length;
       col = arr[0].length;

        for (int i = 0; i < arr.length; i++) {
            for (int j = 0; j < arr[i].length; j++) {
               if (arr[i][j] != 0){
                  list.add(new Triple(i,j,arr[i][j])) ;
                  count++;
               }
            }
        }
    }

    public void test(){

        list.add(null);
    }

    public int getRow() {
        return row;
    }

    public void setRow(int row) {
        this.row = row;
    }

    public int getCol() {
        return col;
    }

    public void setCol(int col) {
        this.col = col;
    }

    public List<Triple> getList() {
        return list;
    }

    public void setList(List<Triple> list) {
        this.list = list;
    }

    public int[][] decompression() {
        int[][] temp = new int[row][col];

        //迭代
        Iterator<Triple> iterator = list.iterator();
        while (iterator.hasNext()){
            Triple triple = iterator.next();
            temp[triple.getRow()][triple.getCol()] = triple.getValue();
        }
        return temp;

       /* for (Triple:list) {

        }*/

    }
}
